package com.java.imauoj.sercive;

import com.java.imauoj.mapper.ProblemMapper;
import com.java.imauoj.moudel.*;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProblemService {

    @Autowired
    private ProblemMapper mapper;

    public List getProblemList(FanHuiZhi fanHuiZhi){
        String sql = fanHuiZhi.getSql();
        String[] sz = fanHuiZhi.getFhz();
        List<Problem> list = mapper.getProblemList(sql,sz);
        return list;
    }

    public void updateProblem(Problem problem, ProblemSelect select){
        mapper.updateProblem(problem);
        mapper.updateProblemSelect(select);
    }
    public void updateProblem(Problem problem, ProblemGap gap){
        mapper.updateProblem(problem);
        mapper.updateProblemGap(gap);
    }
    public void updateProblem(Problem problem, ProblemProg prog){
        mapper.updateProblem(problem);
        mapper.updateProblemProg(prog);
    }




    public void addProblem(Problem problem,ProblemSelect select){
        mapper.addProblem(problem);
        mapper.addProblemSelect(select);
    }
    public void addProblem(Problem problem,ProblemGap gap){
        mapper.addProblem(problem);
        mapper.addProblemGap(gap);
    }
    public void addProblem(Problem problem,ProblemProg prog){
        mapper.addProblem(problem);
        mapper.addProblemProg(prog);
    }

    public Problem getProblem(Problem problem){
        return mapper.getProblem(problem.getProblem_id());
    }

    public Problem getProblem(Problem problem,int f){
        Problem pro = mapper.getProblem(problem.getProblem_id());
        if(f==1){
            ProblemSelect select = mapper.getProblemSelect(problem.getProblem_id());
            pro.setType(select);
        }else if(f==2){
            ProblemGap gap = mapper.getProblemGap(problem.getProblem_id());
            pro.setType(gap);
        }else{
            ProblemProg prog = mapper.getProblemProg(problem.getProblem_id());
            pro.setType(prog);
        }
        return pro;
    }




    public void deleteProblem(Problem problem,ProblemSelect select){
        mapper.deleteProblem(problem.getProblem_id());
        mapper.deleteProblemSelect(select.getProblem_id());
    }
    public void deleteProblem(Problem problem,ProblemGap gap){
        mapper.deleteProblem(problem.getProblem_id());
        mapper.deleteProblemGap(gap.getProblem_id());
    }
    public void deleteProblem(Problem problem,ProblemProg prog){
        mapper.deleteProblem(problem.getProblem_id());
        mapper.deleteProblemProg(prog.getProblem_id());
    }
}
